package com.ljb.okgodemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.google.gson.reflect.TypeToken;
import com.ljb.lib_http.HttpCallback;
import com.ljb.lib_http.HttpLoaderStratergy;

import java.util.List;


public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private String url = "http://www.wanandroid.com//hotkey/json";
    private String url2 = "http://192.168.1.250:8080/demo/getList";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    public void testGet(View view) {
        HttpLoaderStratergy.getLoader().get(url, null, this, HotKeyBean.class, new HttpCallback<HotKeyBean>() {
            @Override
            public void onSucess(HotKeyBean data) {
                Log.e(TAG, "onSucess: " + JSON.toJSON(data));
            }

            @Override
            public void onError() {
                Log.e(TAG, "onError: ");
            }
        });
    }

    public void testPost(View view) {
        HttpLoaderStratergy.getLoader().post(url, null, this, HotKeyBean.class, new HttpCallback<HotKeyBean>() {
            @Override
            public void onSucess(HotKeyBean data) {
                Log.e(TAG, "onSucess: " + JSON.toJSON(data));
            }

            @Override
            public void onError() {
                Log.e(TAG, "onError: ");

            }
        });

    }

    public void testGetList(View view) {
        HttpLoaderStratergy.getLoader().post(url2, null, this, new TypeToken<List<Persion>>() {
        }.getType(), new HttpCallback<List<Persion>>() {
            @Override
            public void onSucess(List<Persion> data) {
                Log.e(TAG, "onSucess: " + JSON.toJSON(data));

            }

            @Override
            public void onError() {
                Log.e(TAG, "onError: ");

            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        HttpLoaderStratergy.getLoader().stop(this);
    }
}
